package com.example.eventmechanism;

import android.content.res.Configuration;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import androidx.appcompat.app.AppCompatActivity;

public class InformationActivity extends AppCompatActivity {

    EditText ori;
    EditText navigation;
    EditText touch;
    EditText mnc;

    @Override
    protected void onCreate(Bundle saveInstanceState) {
        super.onCreate(saveInstanceState);
        setContentView(R.layout.activity_information);

        ori=(EditText)findViewById(R.id.edit_text1);
        navigation=(EditText)findViewById(R.id.edit_text2);
        touch=(EditText)findViewById(R.id.edit_text3);
        mnc=(EditText)findViewById(R.id.edit_text4);
        Button bn=(Button)findViewById(R.id.button_getInform);

        //为按钮绑定时间监听器
        bn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View source) {
                //获取系统的Configuration对象
                Configuration cfg=getResources().getConfiguration();
                String screen=cfg.orientation==Configuration.ORIENTATION_LANDSCAPE
                        ? "横向屏幕" : "竖向屏幕";
                String naviName = cfg.orientation == Configuration.NAVIGATION_NONAV
                        ? "没有方向控制" : cfg.orientation == Configuration.NAVIGATION_WHEEL
                        ? "滚轮方向控制" : cfg.orientation == Configuration.NAVIGATION_DPAD
                        ? "方向键控制方向" : "轨迹球控制方向";
                String touchName = cfg.touchscreen == Configuration.TOUCHSCREEN_NOTOUCH
                        ? "无触摸屏" : cfg.touchscreen == Configuration.TOUCHSCREEN_STYLUS
                        ? "触摸笔式触摸屏" : "接收手指的触摸屏";
                String mncCode = cfg.mcc + "";
                ori.setText(screen);
                navigation.setText(naviName);
                touch.setText(touchName);
                mnc.setText(mncCode);
            }
        });
    }
}